<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>留存统计</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="__PUBLIC__/layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="__PUBLIC__/layuiadmin/style/admin.css" media="all">
<body layadmin-themealias="default" style="">
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-form layui-card-header layuiadmin-card-header-auto">
            <div class="layui-form-item" style="height: 20px;line-height: 20px;">
                <div class="layui-inline" style="margin-right: 0px;">
                     <span class="layui-breadcrumb">
                        <a href="">首页/留存统计</a>
                        </span>
                </div>
                <div class="layui-inline" style="right: 0px;position: absolute;">
                    <a class="layui-btn layui-btn-small" style="line-height:20px;margin-top:-6px;float:right" href="javascript:location.replace(location.href);" title="刷新">
                        &nbsp;<i class="layui-icon layui-icon-refresh-3" style="line-height:18px;left: 12px;top:12px;"></i>&nbsp;
                    </a>
                </div>
            </div>
        </div>
        <div class="layui-form layui-card-header layuiadmin-card-header-auto">
            <div class="layui-form-item">
                <div class="layui-inline" style="margin-right: 0px;">
                    <label class="layui-form-label">时间</label>
                    <div class="layui-input-inline">
                        <input class="layui-input" placeholder="开始时间" name="start_time" id="start" value="{$time}">
                    </div>
                    <div class="layui-input-inline">
                        <input class="layui-input" placeholder="结束时间" name="end_time" id="end" value="{$end}">
                    </div>

                </div>

                <div class="layui-inline" style="margin-right: 0px;">
                    <button class="layui-btn layuiadmin-btn-admin" lay-submit="" lay-filter="LAY-user-back-search">
                        搜索
                    </button>
                </div>
            </div>
        </div>
        <div class="layui-card-body">
            <table class="layui-table" id="admin_table" lay-filter="admin_table"></table>
            <script type="text/html" id="table_game_player">

            </script>
        </div>
    </div>
</div>

<script src="__PUBLIC__/layuiadmin/layui/layui.js"></script>
<script>
    layui.config({
        base: '__PUBLIC__/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'table','laydate','admin'], function(){
        var $ = layui.$
            ,form = layui.form
            ,admin = layui.admin
            ,table = layui.table,laydate = layui.laydate;



        //时间范围
        laydate.render({
            elem: '#start'
            ,type: 'date'
        });
        //时间范围
        laydate.render({
            elem: '#end'
            ,type: 'date'
        });

        $(".layuiadmin-btn-admin").on("click",function(){

            var starttime = $("#start").val();
            var endtime = $("#end").val();

            table.reload('admin_table',{
                page:{
                    curr:1
                }
                ,where:{starttime:starttime,endtime:endtime}
            });
        });

        /* table.on('toolbar(admin_table)', function(obj){
             var data = obj.data;
            // console.log(data);
             if(data===undefined){
                 layer.msg('数据为空');
             }else{
                // console.log(data.time);
                // console.log(data.currentscore);
                // n=[]
             }
           //  layer.msg(data);
         });*/

        var gameid = $("input[name=gameid]").val();
        var time = $("#start").val();
        var indxe = layer.load(3);
        //执行一个 table 实例
        table.render({
            elem: '#admin_table'
            ,url: 'getliucun' //数据接口
            ,title: '留存统计'
            ,toolbar: true //开启工具栏，此处显示默认图标，可以自定义模板，详见文
            ,defaultToolbar:['filter','exports']
            ,loading:true
            ,page: true //开启分页
            ,cols: [[ //表头
                {field: 'time', title: '时间',align:'center', width:200}
                ,{field: 'login_peo', align:'center', title: '登录用户数', width:120}
                ,{field: 'reg_count', title: '新增用户数', width:160}
                ,{field: 'd1', title: '次日留存', width:140}
                ,{field: 'd2', title: '三日留存'}
                ,{field: 'd3', title: '四日留存'}
                ,{field: 'd4', title: '五日留存'}
                ,{field: 'd5', title: '六日留存'}
                ,{field: 'd6', title: '七日留存'}

            ]]
            ,where:{gameid:gameid,time:time}
            ,done:function (res) {
                layer.close(indxe);
                $.ajax({
                    type:'get',
                    dataType:"json",
                    url:'/index.php/Stats/updatekeep',
                    success:function (data) {
                        console.log(data);
                    },
                    error:function () {
                        layer.msg('发生错误', {icon: 2});
                    },
                });
                // axisLabel:{interval:0},
            }
        });
    });
</script>
</body>
</html>